package com.qkst.website.web.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qkst.website.web.bean.AccessoryBean;
import com.qkst.website.web.mapper.AccessoryMapper;
import com.qkst.website.web.service.AccessoryService;

/**
 * @author lihao
 * @description 评论 service
 * @date 2017-05-12
 * @email ahlxlihao@163.com
 *
 */
@Service("accessoryService")
@Transactional
public class AccessoryServiceImpl implements AccessoryService {
	
	@Autowired
	private AccessoryMapper accessoryMapper;
	
	
	/**
	 * 根据条件查询附件
	 * @param comment
	 * @return List<AccessoryBean>
	 */
	public List<AccessoryBean> queryAccessoryList(AccessoryBean accessory){
		//分页计算
		return accessoryMapper.selectAccessoryList(accessory);
	}
	
	/**
	 * 查询附件总记录数
	 * @param comment
	 * @return 
	 */
	@Override
	public int queryCount(AccessoryBean accessory) {
		return accessoryMapper.selectCount(accessory);
	}

	
	/**
	 * 添加附件
	 * @param accessory
	 * 
	 */
	@Override
	public void save(AccessoryBean accessory,Map<String, Object> result) {
		accessory.setCreateTime(new Date());
		accessory.setLastUpdate(new Date());
		int num=accessoryMapper.insert(accessory);//插入
		result.put("accessory",accessory);
		if(num>0){//插入成功
			result.put("isSuccess", true);
			result.put("code", "000");
		}else{//插入失败
			result.put("isSuccess", false);
			result.put("code", "500");
		}
	}
	
	/**
	 * 删除附件
	 * @param accessory
	 * @return 
	 */
	@Override
	public void delete(AccessoryBean accessory, Map<String, Object> result) {
		if(accessory.getAccessoryId()!=null){
			int num=accessoryMapper.deleteByPrimaryKey(accessory.getAccessoryId());
			result.put("accessory",accessory);
			if(num>0){//删除成功
				result.put("isSuccess", true);
				result.put("code", "000");
			}else{//删除失败
				result.put("isSuccess", false);
				result.put("code", "500");
			}
		}else{
			result.put("isSuccess", false);
			result.put("code", "404");
		}
	}
	
}
